Return to start page
Core/General/Library Player.j
1 library ALibraryCoreGeneralPlayer
2
3 /**
4 * Checks whether a player is a playing user.
5 * @author Tamino Dauth
6 */
7 function IsPlayerPlayingUser takes player whichPlayer returns boolean
8 return ((GetPlayerController(whichPlayer) == MAP_CONTROL_USER) and (GetPlayerSlotState(whichPlayer) == PLAYER_SLOT_STATE_PLAYING))
9 endfunction
10
11 /**
12 * @author Tamino Dauth
13 * @return Returns the number of playing users in game.
14 */
15 function CountPlayingUsers takes nothing returns integer
16 local integer result = 0
17 local player user
18 local integer i = 0
19 loop
20 exitwhen (i == bj_MAX_PLAYERS)
21 set user = Player(i)
22 if (IsPlayerPlayingUser(user)) then
23 set result = result + 1
24 endif
25 set user = null
26 set i= i + 1
27 endloop
28 return result
29 endfunction
30
31 /**
32 * @author Tamino Dauth
33 * @return Returns the number of playing players in game (without neutral players).
34 */
35 function CountPlayingPlayers takes nothing returns integer
36 local integer result = 0
37 local player whichPlayer
38 local integer i = 0
39 loop
40 exitwhen (i == bj_MAX_PLAYERS)
41 set whichPlayer = Player(i)
42 if (GetPlayerController(whichPlayer) == MAP_CONTROL_COMPUTER or IsPlayerPlayingUser(whichPlayer)) then
43 set result = result + 1
44 endif
45 set whichPlayer = null
46 set i= i + 1
47 endloop
48 return result
49 endfunction
50
51 endlibrary